package com.study.jvm.demo.stringtable;

import org.junit.Test;

public class StringNewTest {

    public static void main(String[] args) {
        StringNewTest junit = new StringNewTest();
        junit.test0();
        junit.test1();
        junit.test2();
    }

    @Test
    public void test0() {
        String s3 = new String("1") + new String("1");
        s3.intern();
        String s4 = "11";
        System.out.println(s3 == s4); // false
        System.out.println();
    }

    @Test
    public void test1() {
        String s1 = new String("4") + new String("5");
        s1.intern();
        String s2 = "45";
        System.out.println(s1 == s2);//true

        String s3 = new String("2") + new String("3");
        s3.intern();
        String s4 = "23";
        System.out.println(s3 == s4);//true
        System.out.println();
    }

    @Test
    public void test2() {
        String s1 = new String("ja1") + new String("va1");
        s1.intern();
        String s2 = "ja1va1";
        System.out.println(s1 == s2);//false

        String s3 = new String("Jun1") + new String("it1");
        s3.intern();//false
        String s4 = "Jun1it1";
        System.out.println(s3 == s4);//false
        System.out.println();
    }
}
